import { UploadQuestion, InputQuestion, QuestionBase, TimeQuestion, SelectQuestion, RadioQuestion, TextQuestion } from '@/components/public-template';
import { regExp } from '@/utils/regExp';
import { Api as ApiResource } from '@/config/api/resourceFileInfo';
import { Api } from '@/config/api/documentValidation';
import { getMenNum } from '@/utils';
class HomeService {
  // 基础信息
  getQuestions() {
    const questions: QuestionBase<any>[] = [
      new TextQuestion({
        key: 'code',
        label: '单据编号',
        value: null
      }),
      new TextQuestion({
        key: 'creatorName',
        label: '创建人',
        value: null
      }),
      new TextQuestion({
        key: 'deptName',
        label: '创建部门',
        value: null
      }),
      new TextQuestion({
        key: 'remindDatetime',
        label: '到期提醒时间',
        value: null
      }),
      new TextQuestion({
        key: 'createdTime',
        label: '创建时间',
        value: null
      })
    ];
    return questions;
  }

  // 培训安排
  getArrangeQuestions(showType) {
    const viewQuestions: QuestionBase<any>[] = [
      new TextQuestion({
        key: 'organizer',
        label: '培训组织者',
        value: null
      }),
      new TextQuestion({
        key: 'trainDate', //改
        label: '培训日期',
        value: null
      }),
      new TextQuestion({
        key: 'planDate',
        label: '计划生效日期',
        value: null
      }),
      new TextQuestion({
        key: 'remark',
        label: '备注',
        value: null
      })
    ];
    const questions: QuestionBase<any>[] = [
      new SelectQuestion({
        key: 'organizer',
        label: '培训组织者',
        type: 'text',
        required: true,
        prompt: '请选择',
        value: [],
        state: {
          url: Api.treeDataSubject,
          nameKey: 'nickName',
          nameValue: 'id',
          protType: 'post',
          showSearch: true,
          optionFilterProp: 'label'
        }
      }),
      new TimeQuestion({
        key: 'trainDate',
        label: '培训日期',
        prompt: '请选择',
        required: true,
        value: [],
        state: {
          showTime: true,
          format: 'YYYY-MM-DD HH:mm:ss',
          valueFormat: 'YYYY-MM-DD HH:mm:ss',
          keySplit: ['trainBeignDate', 'trainEndDate']
        }
      }),
      new TimeQuestion({
        key: 'planDate',
        label: '计划生效日期',
        required: true,
        prompt: '请选择',
        value: null,
        type: 'alone',
        state: {
          showTime: true,
          format: 'YYYY-MM-DD HH:mm:ss',
          valueFormat: 'YYYY-MM-DD HH:mm:ss'
        }
      }),
      new InputQuestion({
        key: 'remark',
        label: '备注',
        type: 'textarea',
        value: null,
        reg: regExp.len100,
        prompt: '长度不可超过100个字符'
      })
    ];
    return showType == 'TRAPRE' ? questions : viewQuestions;
  }
  // 培训总结
  getSummaryQuestions(showType, callback) {
    const viewQuestions: QuestionBase<any>[] = [
      new TextQuestion({
        key: 'trainSummary',
        label: '培训总结',
        value: null
      }),
      new UploadQuestion({
        key: 'attachment',
        label: '附件',
        value: null,
        type: 'static',
        state: {
          listType: 'text',
          viewUrl: ApiResource.getPreviewFileUrl,
          params: {},
          previewFile: true,
          fieldNames: {
            fileId: 'id',
            name: 'type',
            size: 'size',
            suffix: 'suffix'
          }
        }
      })
    ];
    const questions: QuestionBase<any>[] = [
      new InputQuestion({
        key: 'trainSummary',
        label: '培训总结',
        required: true,
        type: 'textarea',
        value: null,
        reg: regExp.len100,
        prompt: '长度不可超过100个字符'
      }),
      new UploadQuestion({
        key: 'attachmentFile',
        label: '附件',
        required: true,
        prompt: '请上传',
        value: null,
        controlType: 'upload',
        state: {
          listType: 'text',
          url: ApiResource.resourceUploadFile,
          viewUrl: ApiResource.getPreviewFileUrl,
          cancelLimit: true,
          params: {},
          callback: callback,
          fieldNames: {
            fileId: 'fileId',
            name: 'name',
            size: 'size',
            suffix: 'suffix'
          },
          previewFile: true
        }
      })
    ];
    return showType == 'TRACON' ? questions : viewQuestions;
  }
  // 生效确认
  getConfirmationQuestions(showType) {
    const viewQuestions: QuestionBase<any>[] = [
      new TextQuestion({
        key: 'actualDate',
        label: '生效日期',
        value: null
      })
    ];
    const questions: QuestionBase<any>[] = [
      new RadioQuestion({
        key: 'applyResult', //改
        label: '意见',
        required: true,
        prompt: '请选择',
        value: 1,
        options: [
          {
            label: '通过',
            value: 1
          },
          {
            label: '驳回',
            value: 2
          }
        ],
        state: {
          changeOptions: {
            1: [getMenNum('actualDate', 'hidden', false)],
            2: [getMenNum('actualDate', 'hidden', true)]
          }
        }
      }),
      new InputQuestion({
        key: 'effectRemark',
        label: '备注',
        type: 'textarea',
        reg: regExp.len100,
        prompt: '不可为空，且长度不可超过100个字符'
      }),
      new TimeQuestion({
        key: 'actualDate',
        label: '生效日期',
        required: true,
        prompt: '请选择',
        value: null,
        type: 'alone',
        state: {
          showTime: true,
          format: 'YYYY-MM-DD',
          valueFormat: 'YYYY-MM-DD'
        }
      })
    ];
    return showType == 'EFFCON' ? questions : viewQuestions;
  }
}
export default new HomeService();
